using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPUnitsService 
    {
        ISession session;

        public MRPUnitsService(ISession session)
        {
            this.session = session;
        }
        public MRPUnitsService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpunits(MRPUnits mrpunitsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpunitsX);
            tx.Commit();
        }

        public void UpdateMrpunits(MRPUnits mrpunitsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpunitsX);
            tx.Commit();
        }

        public void DeleteMrpunits(MRPUnits mrpunitsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpunitsX);
            tx.Commit();
        }

        public IList<MRPUnits> GetAllMrpunits(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPUnits");
            IList<MRPUnits> list = query.List<MRPUnits>();
            if (evict)
            {
                foreach (MRPUnits s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPUnits GetAllMrpunitsByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPUnits as c where c.Unitcode= :x");
            query.SetString("x", id);
            MRPUnits s = (MRPUnits)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPUnits> GetMrpunitsByQuery(IQuery query,Boolean evict)
        {
            IList<MRPUnits> list = query.List<MRPUnits>();
            if (evict)
            {
                foreach (MRPUnits s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
